import dgram from 'dgram';
const server = dgram.createSocket('udp4');

server.on('error', (err) => {
    console.log(`服务器异常：\n${err.stack}`);
    server.close();
});

server.on('message', (msg, rinfo) => {
    console.log(`服务器接收到来自 ${rinfo.address}:${rinfo.port} 的 ${msg}`);
    //server.send('大家好啊，我是服务端.');
    //server.send('exit',rinfo.port,rinfo.address)//关闭来自app2.js的链接
    server.send('大家好啊，我是服务端.', rinfo.port);
});

server.on('listening', () => {
    const address = server.address();
    console.log(`服务器监听 ${address.address}:${address.port}`);
});

server.bind(8060);
// 服务器监听 0.0.0.0:41234